package com.gwnet.shop.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.domain.vo.SpecGroupVo;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gwnet.shop.domain.ShopCart;
import com.gwnet.shop.service.IShopCartService;

import javax.annotation.Resource;

/**
 * 购物车Controller
 * 
 * @author zhangwanpeng
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/cart")
public class ShopCartController extends MBaseController
{
    @Resource
    private IShopCartService shopCartService;

    /**
     * 查询购物车列表
     */
    @SaCheckPermission("shop:cart:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopCart shopCart)
    {
        startPage();
        List<SpecGroupVo> list = shopCartService.selectShopCartList(shopCart);
        return getDataTable(list);
    }

    /**
     * 获取购物车详细信息
     */
    @SaCheckPermission("shop:cart:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopCartService.selectShopCartById(id));
    }

    /**
     * 新增购物车
     */
    @SaCheckPermission("shop:cart:add")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopCart shopCart)
    {
        return toAjax(shopCartService.insertShopCart(shopCart));
    }

    /**
     * 修改购物车
     */
    @SaCheckPermission("shop:cart:edit")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopCart shopCart)
    {
        return toAjax(shopCartService.updateShopCart(shopCart));
    }

    /**
     * 删除购物车
     */
    @SaCheckPermission("shop:cart:remove")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopCartService.deleteShopCartByIds(ids));
    }
}
